#include<iostream>
#include<string>
#include <mysql/mysql.h> 

using namespace std;
int main(int argc,char* argv[]){
    //初始化Mysql句柄
    MYSQL *con =mysql_init(NULL);
    //连接数据库
    auto ret = mysql_real_connect(con,"127.0.0.1","root","zxy123456"
    ,"tallyBook",0,NULL,CLIENT_MULTI_STATEMENTS);
    if(ret==nullptr){
        cout<<"connect datdabasa fail"<<endl;
        return -1;
    }
    //查询数据库
    auto search_res = mysql_query(con,"select * from user;");
    //获取查询结果
    auto result =mysql_store_result(con);
    int col = mysql_num_fields(result);
    int row=mysql_num_rows(result);

    if(search_res==0&&row!=0){
        for(int i=0;i<result->row_count;i++){
            auto info=mysql_fetch_row(result);
            cout<<"id:"<<info[0]<<"name"<<info[1]<<"passwd"
            <<info[2]<<endl;
        }
    }
        return 0;
}